using System;
using System.Reflection;
using Core.Interfaces;
using NHibernate;

namespace Core.Domain.Bases
{
  ///<summary>Base for all Entities</summary>
  public abstract class EntityBase
  {
    protected EntityBase()
    {
    }

    ///<summary>Default to true</summary>
    public virtual bool IsValid
    {
      get { return true; }
    }
  }


  public static class Extensions
  {
    ///<summary>Save this entity</summary>
    ///<param name="item"></param>
    ///<typeparam name="T"></typeparam>
    ///<returns></returns>
    public static bool Save<T>(this T item) where T : EntityBase
    {
      var session = IoC.Container.Resolve<ISessionProvider>().GetSession(false);
      using (var trans = session.BeginTransaction())
      {
        session.SaveOrUpdate(item);
        trans.Commit();
      }
      return true;
    }
    
  }
}